import { Entity, PrimaryGeneratedColumn, Column, Index } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";

/**
 * 金币交易订单表
 * shop_type: 1=求购, 2=出售
 * state: 0=挂单中, 1=部分成交, 2=已完成, 3=已撤单
 */
@Entity("gold_trade_order")
@ManualTimestamp()
export class GoldTradeOrderEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Index()
  @Column("int", { comment: "角色ID(下单人)" })
  characterId!: number;

  @Column("tinyint", { comment: "订单类型:1求购,2出售" })
  shop_type!: number;

  @Index()
  @Column("int", { comment: "价格(银两/枚)", unsigned: true })
  price!: number;

  @Column("int", { comment: "下单数量(枚)", unsigned: true })
  count!: number;

  @Column("int", { comment: "剩余未成交数量(枚)", unsigned: true })
  remaining!: number;

  @Column("tinyint", { comment: "订单状态", default: 0 })
  state!: number;

  // 冻结金额/数量(用于简单冻结策略)
  @Column("int", { comment: "冻结银两", default: 0 })
  frozen_silver!: number;

  @Column("int", { comment: "冻结金币(枚)", default: 0 })
  frozen_gold!: number;

  @Column("datetime", { name: "created_at" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true })
  updated_at!: Date | null;
}
